import net.minidev.json.JSONObject;

import java.util.Arrays;
import java.util.List;

/**
 * @Author lzc
 * @Date 2023/2/10 15:00
 */
public class DelKeyDemo {
    public static void main(String[] args) {
        JSONObject data = new JSONObject();
        data.put("a", 97);
        data.put("b", 98);
        data.put("c", 99);
    
        System.out.println(data);
    
        List<String> columns = Arrays.asList("b,c".split(","));
    
        // 不能通过 for 循环删除集合
        /*for (String key : data.keySet()) {
            if (!columns.contains(key)) {
                data.remove(key);
            }
            
        }*/
        // 传统的姿势
        /*Iterator<String> it = data.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            if (!columns.contains(key)) {
                it.remove();
            }
        }*/
    
        data.keySet().removeIf(key -> !columns.contains(key));
    
        System.out.println(data);
    
    }
}
